package com.cmpe.av.androidservice;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cmpe.av.logic.ReportLogic;
import com.cmpe.av.model.Report;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class AndroidSearch
 */
@WebServlet("/AndroidSearch")
public class AndroidSearch extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public AndroidSearch() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String reportStatus = request.getParameter("reportStatus");
		String type = request.getParameter("obstacleType");
		String tag = request.getParameter("tag");
		if(tag == null)
			tag ="null";
		if(reportStatus == null)
			reportStatus="null";
		if(type == null)
			type ="null";
		ObjectMapper mapper = new ObjectMapper();
		List<Report> reports=null;
		try {
			reports = new ReportLogic().searchReport(type, 0, 0, tag, reportStatus,0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.getWriter().print(mapper.writeValueAsString(reports));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
